package com.jin.controller;

import com.jin.config.MessageConfig.Message;
import com.jin.pojo.UserJob;
import com.jin.service.UserJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "个人任务")
@RestController
@RequestMapping("/userJob")
@CrossOrigin
public class UserJobController {

    @Autowired
    UserJobService userJobService;

    @ApiOperation(value = "添加任务")
    @PostMapping("/insertUserJob")
    public Message insertUserJob(UserJob userJob) {
        return userJobService.insertUserJob(userJob)>0?Message.success("200").add("success"):Message.fail("400").add("fail");
    }

    @ApiOperation(value = "删除任务")
    @DeleteMapping("/delUserJob")
    public Message delUserJob(Integer id) {
        return userJobService.delUserJob(id)>0?Message.success("200").add("success"):Message.fail("400").add("fail");
    }

    @ApiOperation(value = "更新任务")
    @PutMapping("/updateUserJob")
    public Message updateUserJob(UserJob userJob) {
        return userJobService.updateUserJob(userJob)>0?Message.success("200").add("success"):Message.fail("400").add("fail");
    }

    @ApiOperation(value = "根据ID查任务")
    @GetMapping("/getUserJobById")
    public Message getUserJobById(Integer id) {
        return Message.success("200").add(userJobService.getUserJobById(id));
    }

    @ApiOperation(value = "查询全部任务")
    @GetMapping("/getUserJob")
    public Message getUserJob() {
        return Message.success("200").add(userJobService.getUserJob());
    }

}
